<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" :checked="allChecked" @click="allClicekdFn"/>
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <!-- These are here just to show the structure of the list items -->
      <!-- List items should get the class `editing` when editing and `completed` when marked as completed -->
      <li :class="{completed:item.isDone}" v-for="item,index in list" :key="item.id">
        <div class="view">
          <input class="toggle" type="checkbox" v-model="item.isDone" />
          <label>{{item.name}}</label>
          <button class="destroy" @click="delFn(index)"></button>
        </div>
      </li>
    </ul>
  </section>
</template>

<script>
export default {
  props: ["list"],
  computed: {
    //单选全部选中更改全选按钮
    allChecked(){
     return this.list.every(item=>item.isDone==true)
    }
  },
  methods: {
    allClicekdFn(e){
     this.list.forEach(item=>item.isDone= e.target.checked)
    },
    delFn(index){
      this.$emit("del-todo",index)
    }
  }
};
</script>

<style>
</style>